home *** CD-ROM | disk | FTP | other *** search
- // Chap14_1.cpp
- #include <iostream.h>
- #include <string.h>
- class Student
- {
- public:
- //conventional constructor
- Student(char *pName = "no name", int ssId = 0)
- {
- cout << "Constructing new student " << pName << "\n";
- strncpy(name, pName, sizeof(name));
- name[sizeof(name) - 1] = '\0';
- id = ssId;
- }
-
- //copy constructor
- Student(Student &s)
- {
- cout << "Constructing Copy of " << s.name << "\n";
- strcpy(name, "Copy of ");
- strcat(name, s.name);
- id = s.id;
- }
- ~Student()
- {
- cout << "Destructing " << name << "\n";
- }
- protected:
- char name[40];
- int id;
- };
-
- //fn - receives its argument by value
- void fn(Student s)
- {
- cout << "In function fn()\n";
- }
-
- int main()
- {
- Student randy("Randy", 1234);
- cout << "Calling fn()\n";
- fn(randy);
- cout << "Returned from fn()\n";
- return 0;
- }
-